/*

=============================================================================

Copyright (c) 2010 Xiotex Studios Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by Xiotex Studios Ltd (http://xiotexstudios.com) and Oladotun Rominiy",
in the same place and form as other third-party acknowledgments. Alternately,
this acknowledgment may appear in the software itself, in the same form and
location as other such third-party acknowledgments.
 
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. 

=============================================================================

File:		CSWF.h
Author:		Byron Atkinson-Jones

Update(s):	(Ola)Dotun Rominiyi (28/10/2010) - replaced built-in types for
											   basic types
											 - shuffled includes for better
											   compilation times
											 - switched initialisation to
											   implement the CSWFAbstractStream

=============================================================================

*/


#ifndef __CSWF_H__
#define __CSWF_H__

#include "SWFTypes.h"

// Forward declare all the helper classes

class CSWFStream;
class CSWFTagList;
class CTexture;
class CSWFInterface;
class CSWFAbstractStream;

class CSWF
{
public:
	
	typedef enum INSTRUCTION
	{
		PLACE_SPRITE,
		REMOVE_SPRITE,
		END_OF_FRAME,
	};

	typedef struct _tagCommand
	{
		INSTRUCTION		m_eInstruction;
		float32			m_fScaleX;
		float32			m_fScaleY;
		float32			m_fAngle;
		float32			m_fTX;
		float32			m_fTY;
		float32			m_fAlpha;
		sInt32				m_iDepth;
		uInt32			m_dwTexture;
		float32			m_fWidth;
		float32			m_fHeight;
		
		float32			m_fParentScaleX;
		float32			m_fParentScaleY;
		float32			m_fParentAngle;
		float32			m_fParentTX;
		float32			m_fParentTY;
		bool			m_bSetParent;
		
		char			m_cTextureName[32];
		
	} COMMAND, *PCOMMAND;
	
	
	typedef struct _tagDisplayItem
	{
		uInt32			m_dwTexture;
		float32			m_fWidth;
		float32			m_fHeight;
		PCOMMAND		m_pCommand;
		
		float32			m_fX;
		float32			m_fY;
		float32			m_fX1;
		float32			m_fY1;
		
		float32			m_fScaleX;
		float32			m_fScaleY;
		float32			m_fAngle;
		float32			m_fTX;
		float32			m_fTY;
		
	} DISPLAY_ITEM, *PDISPLAY_ITEM;

public:
	CSWF();
	~CSWF();
	bool Initialise(const std::string& strPath, CSWFInterface* pInterface);
	bool Initialise(CSWFAbstractStream* pSourceStream, CSWFInterface* pInterface);
	void Shutdown();
	void Reset();
	void Play(float32 fTimeDelta);
	void Render(float32 fCentreX, float32 fCentreY, float32 fScale, float32 fAngle, bool bFlipX, bool bFlipY);

protected:
	bool SetupFromStream(CSWFInterface* pInterface);
	void PlayFrame();
	void Transform(float32 fX, float32 fY, float32 fTX, float32 fTY, float32 fCentreX, float32 fCentreY, float32 fScaleX, float32 fScaleY, float32 fAngle, bool bFlipX, bool bFlipY, float32 fWorldAngle, float32 fWorldScale, float32* fXOut, float32* fYOut); 
	
protected:
	CSWFStream*						m_pStream;
	CSWFTagList*					m_pTagList;
	CSWFInterface*					m_pInterface;

	// Movie information
	uInt32							m_dwFlashVersion;
	uInt32							m_dwSizeOfFile;
	uInt32							m_dwFrameRate;
	uInt32							m_dwFrameCount;
	uInt32							m_dwIndexToStartOfMovie;
	uInt32							m_dwSize;
	SWF_RECT						m_rMovieDimensions;
	
	float32							m_fHalfWidth;
	float32							m_fHalfHeight;

	float32							m_fTime;
	float32							m_fDelta;
	float32							m_fAccumulator;
	
	// Command stream
	std::vector<PCOMMAND>			m_vCommands;
	std::vector<PCOMMAND>::iterator	m_it;
	
	// The display list - making it 30 deep.
	sInt32							m_iHighestLayer;
	DISPLAY_ITEM					m_vDisplayList[30];
	


};


#endif // __CSWF_H__


